/**
 * @(#)ChannelApkInfoImpl.java 2016年9月22日
 * Copyright(C) 2015 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsbd.boss.annotation.SystemControllerLog;
import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.dao.IChannelApkConfigDAO;
import org.jsbd.boss.domian.ChannelApkInfo;
import org.jsbd.boss.domian.RetentPayConfig;
import org.jsbd.boss.domian.channel.ApkPRIConfig;
import org.jsbd.boss.domian.channel.ApkRetentConfig;
import org.jsbd.boss.domian.channel.ChannelApkConfig;
import org.jsbd.boss.domian.channel.ChannelApkConfigDto;
import org.jsbd.boss.domian.channel.RetentLogConfig;
import org.jsbd.boss.domian.channel.TasktimeDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * TODO 请加入本类的说明
 * 
 * @author <a href="mailto:zhangbinghua@zhexinit.com" >zbh</a>
 * @version 1.0.0
 */
@Service
public class ChannelApkConfigDAOImpl extends CrackBaseDao implements IChannelApkConfigDAO {
	public static final Logger LOGGER = LoggerFactory.getLogger(ChannelApkConfigDAOImpl.class);

	@Override
	public Integer insertConfig(ChannelApkConfig channelApkInfo) {
		return super.update("qy_channel_config.INSERT_CONFIG", channelApkInfo);
	}

	@Override
	public Integer deleteConfig(String mark) {
		return super.update("qy_channel_config.DELETE_CONFIG", mark);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.dao.IChannelApkConfigDAO#selectApks(org.jsbd.boss.domian
	 * .channel.ChannelApkConfig)
	 */
	@Override
	public List<ApkRetentConfig> selectAllRetentAPkInfos(ApkRetentConfig config) {
		return super.queryForList("qy_channel_config.SELECT_ALL_RETENT_APK_INFO", config);
	}

	@Override
	public List<ApkRetentConfig> selectAllRetentConfigs() {
		return super.queryForList("qy_channel_config.SELECT_ALL_RETENT_APK");
	}

	@Override
	public List<ChannelApkConfig> selectAllSimpleApk() {
		return super.queryForList("qy_channel_config.SELECT_ALL_SIMPLE_APK");
	}

	@Override
	public List<ChannelApkConfig> selectApkInfos(ChannelApkConfig config) {
		return super.queryForList("qy_channel_config.SELECT_ALL_APK_INFO", config);
	}

	@Override
	public List<ApkPRIConfig> selectApkListOfLogin(ApkPRIConfig config) {
		return super.queryForList("qy_channel_config.SELECT_APK_LIST_OF_LOGIN", config);
	}

	@Override
	public List<ApkPRIConfig> selectApkListOfProvince(ApkPRIConfig config) {
		return super.queryForList("qy_channel_config.SELECT_APK_LIST_OF_PROVINCE", config);
	}

	@Override
	public List<ChannelApkConfig> queryApkInfos(ChannelApkConfig config) {
		return super.queryForList("qy_channel_config.SELECT_USEFUL_APK_INFO", config);
	}

	@Override
	public List<ChannelApkConfig> queryApkList(ChannelApkConfig config) {
		return super.queryForList("qy_channel_config.SELECT_APK_LIST", config);
	}

	@Override
	@SystemControllerLog(description = "更新配置")
	public Integer updateConfig(ChannelApkConfig apkConfig) {
		return super.update("qy_channel_config.UPDATE_CONFIG", apkConfig);
	}
	
	@Override
	@SystemControllerLog(description = "更新配置")
	public Integer updateConfigForBatch(ChannelApkConfig apkConfig) {
		return super.update("qy_channel_config.UPDATE_CONFIG_FOR_BATCH", apkConfig);
	}

	@Override
	public List<ChannelApkConfig> selectApkConfigs(ChannelApkConfig config) {
		return super.queryForList("qy_channel_config.SELECT_APK_CONFIGS", config);
	}

	@Override
	public int getCountOfConfig(ChannelApkConfig config) {
		return super.queryForCount("qy_channel_config.SELECT_COUNT_CONFIG", config);
	}

	@Override
	public List<ChannelApkConfig> selectApkConfigsAndSimulator() {
		return super.queryForList("qy_channel_config.SELECT_APK_CONFIGS_AND_SIMULATOR");
	}

	@Override
	public void updateDaylimit(List<ChannelApkConfig> channelApkConfigs) {
		super.batchUpdate("qy_channel_config.UPDATE_DAY_LIMIT", channelApkConfigs);
	}

	@Override
	public ChannelApkConfig getByMark(String mark) {
		return (ChannelApkConfig) queryForObject("qy_channel_config.GET_BY_MARK", mark);
	}

	@Override
	public List<Map<String, String>> findApknameByMarks(List<String> marks) {
		return super.queryForList("qy_channel_config.SELECT_APKNAME_BY_MARKS", marks);
	}

	@Override
	public List<TasktimeDto> selectTasktimeByBaseList() {
		return super.queryForList("qy_channel_config.SELECT_TASKTIME_BY_BASE_LIST");
	}

	@Override
	public List<String> selectAndriodVerList() {
		return super.queryForList("qy_channel_config.SELECT_ANDRIOD_VER_LIST");
	}

	@Override
	public Map<String, Object> selectAllRetentMarkInfo(DataGridModel page, RetentPayConfig retentPayConfig) {
		retentPayConfig = (retentPayConfig == null ? new RetentPayConfig() : retentPayConfig);
		retentPayConfig.setPageInfo(page);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("rows", super.queryForList("qy_channel_config.SELECT_ALL_RETENT_MARK_LIST", retentPayConfig));
		map.put("total", super.queryForCount("qy_channel_config.SELECT_ALL_RETENT_MARK_COUNT", retentPayConfig));
		return map;
	}

	@Override
	public List<ApkRetentConfig> selectRetentFillApkList(RetentLogConfig config) {
		return super.queryForList("qy_channel_config.SELECT_RETENT_FILL_APK_INFO", config);
	}

	@Override
	public void batchUpdateConfig(ChannelApkConfig apkConfig) {
		super.update("qy_channel_config.BATCH_UPDATE_CONFIG", apkConfig);
	}

	@Override
	public List<ChannelApkConfig> getAllMarkAndApkname() {
		return super.queryForList("qy_channel_config.SELECT_ALL_MARK_AND_APKNAME");
	}

	@Override
	public void updateModifyTime(ChannelApkConfig apkConfig) {
		super.update("qy_channel_config.UPDATE_MODIFY_TIME", apkConfig);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.dao.IChannelApkConfigDAO#copyConfig(org.jsbd.boss.domian
	 * .channel.ChannelApkConfig)
	 */
	@Override
	public void copyConfig(ChannelApkConfig apkConfig) {
		super.insert("qy_channel_config.COPY_CONFIG_PROVINCE", apkConfig);
		super.insert("qy_channel_config.COPY_CONFIG_LOGINTYPE", apkConfig);
		super.insert("qy_channel_config.COPY_CONFIG_RETENT_FILTER", apkConfig);
		super.insert("qy_channel_config.COPY_CONFIG_DEVICE", apkConfig);
		super.insert("qy_channel_config.COPY_CONFIG_RETENT", apkConfig);
		super.insert("qy_channel_config.COPY_CONFIG_TIME", apkConfig);
		super.insert("qy_channel_config.COPY_CONFIG_RETENTTIMES", apkConfig);
	}

	@Override
	public void copyRetentTimes(ChannelApkConfig apkConfig) {
		super.insert("qy_channel_config.COPY_CONFIG_RETENTTIMES", apkConfig);
	}


	@Override
	public List<ChannelApkConfigDto> selectConfigApkListByIsdelete(Integer isDelete, List<String> keywords) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("isDelete", isDelete);
		params.put("keywords", keywords);
		return super.queryForList("qy_channel_config.SELECT_CONFIG_APK_LIST_BY_ISDELETE", params);
	}

}
